package app

import (
	"gin_template/data/e"

	"github.com/gin-gonic/gin"
)

type Gin struct {
	C *gin.Context
}

type Response struct {
	Status  string      `json:"status"`
	Message string      `json:"message"`
	Data    interface{} `json:"data"`
}

// Response setting gin.JSON
func (g *Gin) Response(httpCode int, errCode string, data ...interface{}) {
	var res = Response{
		Status:  errCode,
		Message: e.GetMsg(errCode),
	}
	if len(data) == 1 {
		res.Data = data[0]
	} else {
		res.Data = data
	}
	g.C.JSON(httpCode, res)
	return
}

// customerResponse 自定义返回结果
func (g *Gin) customerResponse(httpCode int, errCode string, message string, data interface{}) {
	if message == "" {
		message = e.GetMsg(errCode)
	}
	g.C.JSON(httpCode, Response{
		Status:  errCode,
		Message: message,
		Data:    data,
	})
	return
}
